﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace InsuranceAdjuster
{
    public class ColorHolder : INotifyPropertyChanged
    {
        private Color _bgcolor;


        public Color BackgroundColor
        {
            get { return _bgcolor; }
            set { _bgcolor = value;
            OnPropertyChanged(("BackgroundColor"));}
        }

        private Color _forecolor;
        
        public Color ForegroundColor
        {
            get { return _forecolor; }
            set
            {
                _forecolor = value;
                OnPropertyChanged(("ForegroundColor"));
            }
        }

        public ColorHolder()
        {
            BackgroundColor = GetColorfromHex("#FFFFC800");
            ForegroundColor = GetColorfromHex("#FF625F55");
        }

        private static Color GetColorfromHex(string hex)
        {
            hex = hex.Replace("#", "");

            byte a = 255;
            byte r = 255;
            byte g = 255;
            byte b = 255;
            int start = 0;

            //handle ARGB strings (8 characters long) 
            if (hex.Length == 8)
            {
                a = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
                start = 2;
            }

            //convert RGB characters to bytes 
            r = byte.Parse(hex.Substring(start, 2), System.Globalization.NumberStyles.HexNumber);
            g = byte.Parse(hex.Substring(start + 2, 2), System.Globalization.NumberStyles.HexNumber);
            b = byte.Parse(hex.Substring(start + 4, 2), System.Globalization.NumberStyles.HexNumber);

            return Color.FromArgb(a, r, g, b);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if(PropertyChanged!=null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
